package com.xz.group12306.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.xz.group12306.business.service.ManagerService;
import com.xz.group12306.business.service.impl.ManagerServiceImpl;
import com.xz.group12306.domain.Ticket;

/**
 * 管理员修改车票信息Servlet
 */
@WebServlet("/ManageModifyTicketServlet")
public class ManageModifyTicketServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * 构造方法
	 */
	public ManageModifyTicketServlet() {
		super();
	}

	/**
	 * doGet方法
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		Ticket ticket = new Ticket();
		String TicketID = request.getParameter("ticketid");
		String Depature = request.getParameter("depature");
		String Destinction = request.getParameter("destinction");
		String Trainno = request.getParameter("trainno");
		String CostTime = request.getParameter("costtime");
		String TicketNo = request.getParameter("ticketno");

		ticket.setTicketId(Integer.parseInt(TicketID));
		ticket.setDepature(Depature);
		ticket.setDestinction(Destinction);
		ticket.setTrainNo(Trainno);
		ticket.setCostTime(CostTime);
		ticket.setTicketNo(Integer.parseInt(TicketNo));

		ManagerService managerService=new ManagerServiceImpl();
		managerService.updateTicket(ticket);
		
		List<Ticket> tickets = managerService.findAllTicket();
		HttpSession session = request.getSession();

		session.setAttribute("tickets", tickets);
		response.sendRedirect("admin/UpdateTicket.jsp");

	}

	/**
	 *  doPost方法
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}

}
